home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1760 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  73 lines

  1. Newsgroups: comp.lang.c
  2. Path: uu4news.netcom.com!zodiac!szh
  3. From: szh@zcon.com (Syed Zaeem Hosain)
  4. Subject: Re: A Very Simple Socket Question
  5. Message-ID: <1996Jan16.174631.1892@zcon.com>
  6. Sender: szh@zcon.com (Syed Zaeem Hosain)
  7. Nntp-Posting-Host: zodiac
  8. Reply-To: szh@zcon.com
  9. Organization: Z Consulting Group
  10. References: <4dfgj8$6p9@nntp.ucs.ubc.ca>
  11. Date: Tue, 16 Jan 1996 17:46:31 GMT
  12.  
  13. In article <4dfgj8$6p9@nntp.ucs.ubc.ca>, evil@unixg.ubc.ca (Peter Pan) writes:
  14. >Please help! I am a C beginner.
  15. >
  16. >======================================
  17. >Client:
  18. >
  19. >int sd, addrlen;
  20. >struct sockaddr_in svaddr;
  21. >
  22. >char *data;
  23. >data = "abcdef";
  24. >
  25. >..... /* skip */
  26. >
  27. >sendto(sd, data, strlen(data), 0, &svaddr, &addrlen);
  28. >
  29. >
  30. >==========================================
  31. >Server:
  32. >
  33. >char data;
  34. >data = (char*) malloc( 100*sizeof(char) );
  35. >
  36. >recvfrom(sd2, data, sizeof(data), 0, &claddr, &addrlen);
  37. >
  38. >==========================================
  39. >
  40. >Output:
  41. >
  42. >data sent: abcdef
  43. >data received: abcd
  44. >
  45. >==========================================
  46. >
  47. >Anyone knows why the data are different after transmittion.
  48.  
  49. Well, I do not know if this is the problem (it may be a typo in your
  50. post), but you might try declaring:
  51.  
  52. char *data;
  53.  
  54. on the server, rather than:
  55.  
  56. char data;
  57.  
  58. When you then assign "data = (char *) mall...", the very explicit cast
  59. *probably* (but I am not sure) causes the error messages about this
  60. mistake to be suppressed.
  61.  
  62. Of course, there may still be something more wrong with the socket
  63. transmission. But this is one place to get started.
  64.  
  65.                                 Z
  66.  
  67.  
  68. -- 
  69. -------------------------------------------------------------------------
  70. | Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |
  71. | Z Consulting Group        San Jose, CA 95161             szh@zcon.com |
  72. -------------------------------------------------------------------------
  73.